<template>
  <div class="address-manager-cell">
    <div class="address-manager-cell__contain">
      <div class="address-manager-cell__right">
        <div class="address-manager-cell__right__auth">
          <div class="address-manager-cell__right__auth__name">{{data.recipients}}
          </div>
          <div class="address-manager-cell__right__auth__phone">{{data.cellphone}}</div>
        </div>
        <div class="address-manager-cell__right__address"
             :style="{color:'#666666'}">
          <div class="address-manager-cell__right__address__left">收货地址: </div>
          <div class="address-manager-cell__right__address__right">
            {{data.province}}{{data.city}}{{data.area}}{{data.adress}}
          </div>

        </div>

        <div class="address-manager-cell__right__diving"></div>

        <div class="address-manager-cell__right__bottom">

          <div class="address-manager-cell__right__bottom__left"
               v-on:click="setCheckedImage()">
            <img :src="getCheckedImage()">
            <span>默认地址</span>
          </div>
          <div class="address-manager-cell__right__bottom__right">
            <div v-on:click.stop="editClick()">
              <img src="@image/mk_address_edit.png">
              <span>编辑</span>
            </div>
            <!-- 在编辑和删除之间添加一个空的div，宽度为他们的间距，可以防止点击中间时触发两边的点击事件 -->
            <div></div>
            <div v-on:click.stop="deleClick()">
              <img src="@image/search-history-delete.png">
              <span>删除</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="stylus" scoped>
.address-manager-cell {
  margin-top: 20px;

  .address-manager-cell__contain {
    width: 100%;
    background: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    box-sizing: border-box;
  }

  .address-manager-cell__left {
    margin-top: 50px;
    margin-right: 20px;

    img {
      width: 30px;
    }
  }

  .address-manager-cell__right {
    margin-left: 10px;
    margin-right: 10px;

    .address-manager-cell__right__auth {
      margin-bottom: 20px;
      width: 650px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;

      .address-manager-cell__right__auth__name {
        font-size: 28px;
        width: 420px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1;
        overflow: hidden;

        span {
          margin-left: 9px;
          color: #e31436;
        }
      }

      .address-manager-cell__right__auth__phone {
        font-size: 28px;
      }
    }

    .address-manager-cell__right__address {
      font-size: 26px;
      margin-bottom: 20px;
      display: flex;
      align-items: flex-start;

      .address-manager-cell__right__address__left {
        width: 120px;
      }

      .address-manager-cell__right__address__right {
        // margin-left: 2px;
        width: 530px;
      }
    }

    .address-manager-cell__right__diving {
      width: 100%;
      height: 1px;
      background: #dddddd;
      margin-bottom: 25px;
    }

    .address-manager-cell__right__bottom {
      width: 100%;
      display: flex;
      flex-direction: row;
      margin-bottom: 5px;
      justify-content: space-between;

      .address-manager-cell__right__bottom__left {
        // @include flex-v;
        display: flex;
        flex-direction: row;
        align-items: center;
        height: 30px;
        font-size: 26px;

        img {
          width: 30px;
          height: 30px;
          margin-right: 17px;
        }
      }

      .address-manager-cell__right__bottom__right {
        display: flex;

        div {
          display: flex;
          flex-direction: row;
          align-items: center;
          z-index: 70;
        }

        div:nth-child(2) {
          width: 30px;
        }

        img {
          width: 34px;
          height: 34px;
          margin-right: 15px;
          z-index: 70;
        }

        font-size: 26px;
      }
    }
  }
}
</style>

<script>
export default {
  name: 'address-manager-cell',
  data () {
    return {}
  },
  props: {
    selectedIndex: Number, // 当前选中的“默认地址”的条目下标
    index: Number, // 当前条目的下标
    data: Object,
    area: String
  },
  methods: {
    getSelectedImage: function () {
      if (this.selectedIndex === this.index) {
        return require(`@image/icon-checked.png`)
      } else {
        return require(`@image/icon-unchecked.png`)
      }
    },
    // 选中 以及 未选中 “默认地址” 按钮 的图片切换
    getCheckedImage: function () {
      if (this.data && this.data.flag === '0') {
        return require(`@image/icon-checked.png`)
      } else {
        return require(`@image/icon-unchecked.png`)
      }
    },
    // 点击了 “默认地址”
    setCheckedImage: function () {
      // 如果选中的 和当前索引相同 不作处理
      if (this.data.flag !== '0') {
        this.$emit('switchDefaultSelected', this.index)
      }
    },
    editClick: function () {
      this.$emit('operaItem', this.index, 1)
    },
    deleClick: function () {
      this.$emit('operaItem', this.index, -1)
    }
  }
}
</script>
